package com.hl.ruoyicsmshop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.ruoyicsmshop.domain.KillActivity;
import com.hl.ruoyicsmshop.service.IKillActivityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 秒杀活动Controller
 * 
 * @author ruoyi
 * @date 2025-08-09
 */
@RestController
@RequestMapping("/killActivity")
public class KillActivityController extends BaseController
{
    @Autowired
    private IKillActivityService killActivityService;

    /**
     * 查询秒杀活动列表
     */
    @RequiresPermissions("csmshop:killActivity:list")
    @GetMapping("/list")
    public TableDataInfo list(KillActivity killActivity)
    {
        startPage();
        List<KillActivity> list = killActivityService.selectKillActivityList(killActivity);
        return getDataTable(list);
    }

    /**
     * 导出秒杀活动列表
     */
    @RequiresPermissions("csmshop:killActivity:export")
    @Log(title = "秒杀活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KillActivity killActivity)
    {
        List<KillActivity> list = killActivityService.selectKillActivityList(killActivity);
        ExcelUtil<KillActivity> util = new ExcelUtil<KillActivity>(KillActivity.class);
        util.exportExcel(response, list, "秒杀活动数据");
    }

    /**
     * 获取秒杀活动详细信息
     */
    @RequiresPermissions("csmshop:killActivity:query")
    @GetMapping(value = "/{kaId}")
    public AjaxResult getInfo(@PathVariable("kaId") Long kaId)
    {
        return success(killActivityService.selectKillActivityByKaId(kaId));
    }

    /**
     * 新增秒杀活动
     */
    @RequiresPermissions("csmshop:killActivity:add")
    @Log(title = "秒杀活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KillActivity killActivity)
    {
        return toAjax(killActivityService.insertKillActivity(killActivity));
    }

    /**
     * 修改秒杀活动
     */
    @RequiresPermissions("csmshop:killActivity:edit")
    @Log(title = "秒杀活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KillActivity killActivity)
    {
        return toAjax(killActivityService.updateKillActivity(killActivity));
    }

    /**
     * 删除秒杀活动
     */
    @RequiresPermissions("csmshop:killActivity:remove")
    @Log(title = "秒杀活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{kaIds}")
    public AjaxResult remove(@PathVariable Long[] kaIds)
    {
        return toAjax(killActivityService.deleteKillActivityByKaIds(kaIds));
    }
}
